package com.example.myapplication.tack_17;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.tack_17.adappter.RouteAdapter;
import com.example.myapplication.tack_17.data.RouteData;
import com.example.myapplication.utils.OkHttpTool;

import java.util.List;

public class SmartBusActivity extends AppCompatActivity {
    private ImageView exit;
    private RecyclerView list;
    private RecyclerView arrange;
    private List<RouteData.RowsDTO> listRoute;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_17_activity_smart_bus);
        init();
        exit_();
        getRoute();
    }



    private void getRoute() {
        String url = "prod-api/api/bus/line/list";
        OkHttpTool.doNetRequest(url, OkHttpTool.GET, RouteData.class, new OkHttpTool.NetCallback() {
            @Override
            public void onSuccess(Object obj) {
                RouteData routeData = (RouteData)obj;
                if(routeData.getCode() == 200){
                    listRoute = routeData.getRows();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            RouteAdater();
                        }
                    });
                }
            }


            @Override
            public void onFailure(String msg) {

            }
        });
    }
    private void RouteAdater() {

        RouteAdapter routeAdapter = new RouteAdapter(listRoute, SmartBusActivity.this);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(SmartBusActivity.this);
        list.setLayoutManager(linearLayoutManager);
        list.setAdapter(routeAdapter);
    }


    private void exit_() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SmartBusActivity.this.finish();
            }
        });
    }

    private void init() {
        exit = findViewById(R.id.exit);
        list = findViewById(R.id.list);
        arrange = findViewById(R.id.arrange);

    }
}